<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 政策解读表
 */
class PolicyContent extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\PolicyContent();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }


    /**
     * 列表
     * @return void
     */
    public function list()
    {
        $input = input();
        try {
            $pageArr = [
                'page' => 1,
                'page_limit' => 30,
            ];
            $where = [];
            if (!empty($input['id'])) {
                $where['id'] = $input['id'];
            }
            $pageArr = array_merge($pageArr, $input);
            $data = $this->model
                ->where($where)
                ->order('createtime asc')
                ->paginate([
                    'page' => $pageArr['page'] ?: 1,
                    'list_rows' => $pageArr['page_limit'] ?: 10
                ]);
            $this->success('ok', $data);
        }catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }
}